<?php

function unsDepartement_addMaterial($name, $code, $coefficient, $teachingUnitID, $professeurID, $nbHoursL, $nbHoursWP, $nbHoursT) {
    if (!empty($name) && !empty($code) && !empty($coefficient) && !empty($teachingUnitID) && !empty($professeurID) && !empty($nbHoursL) && !empty($nbHoursWP) && !empty($nbHoursT)) {
        
        global $babDB;
        
        $babDB->db_query("INSERT INTO " . UNSDEPARTEMENT_MATERIALS_TABLE_NAME . " VALUES (null, '$name', '$code', $coefficient, $teachingUnitID, $professeurID, $nbHoursL, $nbHoursWP, $nbHoursT, now(), " . $GLOBALS['BAB_SESS_USERID'] . " );");
    }
}

function unsDepartement_deleteMaterial($id) {
    global $babDB;
    
    $babDB->db_query("DELETE FROM " . UNSDEPARTEMENT_MATERIALS_TABLE_NAME . "WHERE id=".$id);
}

function unsDepartement_getMaterialsForTeachingUnit($id) {

    global $babDB;


    $res = $babDB->db_query("select * from " . UNSDEPARTEMENT_MATERIALS_TABLE_NAME . " where material_teachingUnitID = " . $id);

    $materials = array();
    $i = 0;
    while ($arr = $babDB->db_fetch_array($res)) {
        $materials[$i] = $arr;
        $i++;
    }
    return $materials;
}

function  unsDepartement_getMaterial($id)
{
    global $babDB;


    $res = $babDB->db_query("select id, material_name as name, material_code as code, material_coefficient as coefficient,
        material_teachingUnitID as teachingUnitID,
        material_professortID as professorID,
        material_nbHoursLectures as nbHoursLectures,
        material_nbHoursWorkPratices as nbHoursWorkPratices,
        material_nbHoursTutorials as nbHoursTutorials 
        from " . UNSDEPARTEMENT_MATERIALS_TABLE_NAME . " where id = " . $id);

    $material = $babDB->db_fetch_array($res);

    return $material;
}
?>
